from django.db import models
from pets.models import Pet, CareTaker


class ServiceType(models.Model):
    name = models.CharField(max_length=100)
    description = models.TextField(blank=True)
    duration = models.PositiveIntegerField(help_text="Duration in minutes")
    base_price = models.DecimalField(max_digits=6, decimal_places=2)

    def __str__(self):
        return self.name


class Appointment(models.Model):
    STATUS_CHOICES = [
        ('P', 'Pending'),
        ('C', 'Confirmed'),
        ('R', 'Rejected'),
        ('D', 'Done'),
    ]

    pet = models.ForeignKey(Pet, on_delete=models.CASCADE)
    service = models.ForeignKey(ServiceType, on_delete=models.CASCADE)
    caretaker = models.ForeignKey(CareTaker, on_delete=models.SET_NULL, null=True, blank=True)
    date_time = models.DateTimeField()
    duration = models.PositiveIntegerField(default=60, help_text="Duration in minutes")
    notes = models.TextField(blank=True)
    status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='P')
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.pet.name} - {self.service} on {self.date_time}"
